package com.ly.hotel.view;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.common.MyKeyEventCode;
import com.ly.hotel.service.FxService;


public class AuthTipsActivity extends Activity {

	private Button backBtn;
	private TextView authTips;
	private static boolean flag = true;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_auth_tips);
		authTips = (TextView) findViewById(R.id.authTips);
		if(MyApplication.licenseTimeOut ){
//			if(MyApplication.ukeyInvalidDays >= 0){
				authTips.setText("您的系统已到期，请您联系供应商办理续期，以免影响您的使用。");
//			}
		} else if(!MyApplication.ukeyInvalidTime.equals("")){
			authTips.setText("截止到"+ MyApplication.ukeyInvalidTime + " ，您的系统即将到期，请您联系供应商办理续期，以免影响您的使用。");
		} else {
			finish();
		}
		backBtn = findViewById(R.id.backBtn);
		backBtn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				flag = false;
				AuthTipsActivity.this.finish();
			}
		});
		
		if(MyApplication.licenseTimeOut/*MyApplication.ukeyInvalidDays >= 0 && MyApplication.startUpTimeHour >= 14*/){
			backBtn.setVisibility(View.GONE);
			
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					while(flag){
						// TODO Auto-generated method stub
						try {
							Thread.sleep(200);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}	
						
						if(InitActivity.stopService(MyApplication.getContext(),"FxService",FxService.class)){
							flag = false;
						}
					}
				}
			}).start();
			
		}
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){
			return true;
		}
		
		if(MyKeyEventCode.getAction(keyCode) == MyKeyEventCode.ACTION_SET){
			Intent intent = new Intent(Intent.ACTION_MAIN);
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			intent.setClassName("com.ly.hotel", "com.ly.hotel.view.setting.UserGuideActivity");

			startActivity(intent);
		}
		return super.onKeyDown(keyCode, event);
	}
	
	
}
